enum TitleState{ slideIn = 0, slideOut, activated, deactivated, activate, deactivate }
var title : Texture;
var time : float = 2.0;
var titleSize : float = 0.1;
private var pos1 : Rect;//change to guistyle and use box
private var pos2 : Rect;
//var HUD : GameHUD;

private var startTime : float;
var state : TitleState = TitleState.deactivated;

function OnGUI(){
	GUI.depth = 0;
	GUI.backgroundColor = Color(0,0,0,1);
	if(title){
		GUI.DrawTexture(pos1, title);
		GUI.DrawTexture(pos2, title);
	} else
		Debug.Log("Cinematic Titles: There is no black texture");
}
function Start(){
	pos1 = Rect(0,-Screen.height*titleSize,Screen.width, Screen.height*titleSize);
	pos2 = Rect(0,Screen.height,Screen.width, Screen.height*titleSize);
}
function Update(){
	if(state == TitleState.activate){
		state = TitleState.slideIn;
		startTime = Time.time;
		//HUD.enabled = false;
	} else if(state == TitleState.slideIn){
		pos1.y = -Screen.height*titleSize+((Time.time-startTime)/time)*Screen.height*titleSize;
		pos2.y = Screen.height-((Time.time-startTime)/time)*Screen.height*titleSize;
		if((Time.time-startTime)>=time)
			state = TitleState.activated;
	} else if(state == TitleState.deactivate){
		state = TitleState.slideOut;
		startTime = Time.time;
	} else if(state == TitleState.slideOut){
		pos1.y = -((Time.time-startTime)/time)*Screen.height*titleSize;
		pos2.y = Screen.height*(1-titleSize)+((Time.time-startTime)/time)*Screen.height*titleSize;
		if((Time.time-startTime)>=time){
			state = TitleState.deactivated;
			//HUD.enabled = true;
		}
	}
}
